package com.bjb.vr.manager.controller;

import com.bjb.vr.common.ao.ResFavoriteAo;
import com.bjb.vr.common.result.BaseErrorCode;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.ResFavoritesService;
import io.jsonwebtoken.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收藏夹列表
 *
 * @version 1.0.0
 * @author: HuJingBo
 * @time: 2022/3/22 16:39
 */
@RestController
@RequestMapping("/api/manager/v1")
public class FavoriteController {

    @Autowired
    ResFavoritesService favoriteService;


    /**
     * 根据条件查询我的收藏夹
     *
     * @param resFavoriteAo
     * @return
     */
    @PostMapping("/queryFavorite")
    public BaseResult queryFavorite(@RequestBody ResFavoriteAo resFavoriteAo) {
        return favoriteService.queryFavorite(resFavoriteAo);
    }

    /**
     * 添加到收藏夹
     *
     * @param resFavoriteAo
     * @return
     */
    @PostMapping("/addFavorite")
    public BaseResult addFavorite(@RequestBody ResFavoriteAo resFavoriteAo) {
        Assert.notNull(resFavoriteAo.getResIds(), "resIds不能为空");
        boolean success = favoriteService.addFavorite(resFavoriteAo);
        if (!success) {
            return CommonResult.Fail(BaseErrorCode.ERROR_ADD);
        }
        return CommonResult.Ok();
    }

    /**
     * 从收藏夹删除
     *
     * @param resFavoriteAo
     * @return
     */
    @PostMapping("/removeFavorite")
    public BaseResult removeFavorite(@RequestBody ResFavoriteAo resFavoriteAo) {
        boolean success = favoriteService.removeFavorite(resFavoriteAo);
        if (!success) {
            return CommonResult.Fail(BaseErrorCode.ERROR_REMOVE);
        }
        return CommonResult.Ok();
    }
}
